package com.bright.tactiviti.component.activiti;

import org.activiti.spring.SpringAsyncExecutor;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.AbstractProcessEngineAutoConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.io.IOException;

/**
 *Activiti 的全局配置类
 */

@Configuration
public class ActivitiConfiguration extends AbstractProcessEngineAutoConfiguration {
    private  final DataSource dataSource;
    private  final PlatformTransactionManager platformTransactionManager;

    /**
     * 注入数据源和事务模板
     * @param dataSource   数据源
     * @param platformTransactionManager  事务模板
     */
    @Autowired
    public ActivitiConfiguration(DataSource dataSource, PlatformTransactionManager platformTransactionManager){
        this.dataSource = dataSource;
        this.platformTransactionManager = platformTransactionManager;
    }

    /**
     * 配置流程引擎，activiti最重要的就是流程引擎，这里就是注入dataSource 一些教程会有些使用
     * @param springAsyncExecutor
     * @return
     * @throws IOException
     */
    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration(SpringAsyncExecutor springAsyncExecutor) throws IOException{
        return baseSpringProcessEngineConfiguration(dataSource,platformTransactionManager,springAsyncExecutor);
    }
}
